package org.m8.auth.handler;

import lombok.extern.slf4j.Slf4j;
import org.m8.util.Registry;

/**
 * 登录服务注册器
 *
 * @author yidanjun
 * @date 2024/9/4
 **/
@Slf4j
public class AuthLoginHandlerRegistry {

    private final Registry<String, AbstractAuthLoginHandler> registry;

    private static final AuthLoginHandlerRegistry instance = new AuthLoginHandlerRegistry();

    public static AuthLoginHandlerRegistry getInstance() {
        return instance;
    }
    private AuthLoginHandlerRegistry() {
        registry = new Registry<>();
    }

    /**
     * 注册登录服务客户端
     *
     * @param type 客户端类型
     * @param client 客户端
     */
    public void register(String type, AbstractAuthLoginHandler client) {
        log.info("register config service:{},{}", type, client.getClass());
        registry.register(type, client);
    }

    /**
     * 获取当前的登录服务客户端
     *
     * @return 登录服务客户端
     */
    public AbstractAuthLoginHandler getService(String loginType) {
        return registry.get(loginType);
    }

}
